package tds.model20.version1;

import java.util.ArrayList;
import java.util.List;

/**
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName Composite
 * @Description 组合节点，可以拥有子节点
 * @author tds
 * @Date 2020/2/5 17:32
 * @version 1.0.0
 */
public class Composite extends Component {

    List<Component> children = new ArrayList<>();

    public Composite(String name) {
        super(name);
    }

    @Override
    public void add(Component component) {
        children.add(component);
    }

    @Override
    public void remove(Component component) {
        children.remove(component);
    }

    @Override
    public void display() {
        System.out.println("这是枝节点" + name + "，下面是他的子节点");
        for (Component child : children){
            child.display();
        }

    }
}
